package utils;

import lombok.NoArgsConstructor;

import java.io.*;
import java.util.*;

@NoArgsConstructor
public class StringsInit {

    private int count = 0;

    private Map<String,String> strs = null;

    public StringsInit(int count) {
        super();
        this.count = count;
    }

    public Map<String,String> init(String fileName) {

        try {
            readFromFile(fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return strs;
    }

    private void readFromFile(String fileName) throws Exception {
        InputStream inputStream = Object.class.getResourceAsStream("/"+fileName);
        try (
                InputStreamReader read = new InputStreamReader(inputStream);
                BufferedReader bufRead = new BufferedReader(read);
                ) {
            strs = new HashMap<>(487177);
            String line = null;
            long index = 1L;
            while ((line = bufRead.readLine()) != null) {
                if (count > 0 && index > count) {
                    break;
                }
                line = line.replace("\n", "");
                String[] strings = line.split(":");
                if(strings.length==1){
                    strs.put(strings[0],null);
                }else {
                    strs.put(strings[0],strings[1]);
                }
                ++index;
            }
        }
    }

}
